Use a hash for -C metadata instead of a string
authorAlex Crichton <alex@alexcrichton.com>
Tue, 22 Jul 2014 15:33:47 +0000 (08:33 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 22 Jul 2014 17:06:36 +0000 (10:06 -0700)
This ends up serving the same purpose, but a critical change is that it
canonicalizes the relevant git url (if one is used) to ensure that the same
package from two slightly different locations is always built the same way.

Sadly I'm not quite sure how to add a test for this as it involves using remote
git urls which are unusable during tests.

src/cargo/core/package_id.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
tests/test_cargo_compile.rs
tests/test_cargo_compile_git_deps.rs

index b5d8d9436359be282e1f7e7a9d1a5e14b2fe70f5..51ce421d2909306c6194398cbfc4ccb0b7440643 100644 (file)
@@ -118,11 +118,11 @@ impl PackageId {
     }
 
     pub fn generate_metadata(&self) -> Metadata {
-        let metadata = format!("{}:-:{}:-:{}", self.name, self.version, self.source_id);
-        let extra_filename = short_hash(
+        let metadata = short_hash(
             &(self.name.as_slice(), self.version.to_string(), &self.source_id));
+        let extra_filename = format!("-{}", metadata);
 
-        Metadata { metadata: metadata, extra_filename: format!("-{}", extra_filename) }
+        Metadata { metadata: metadata, extra_filename: extra_filename }
     }
 }
 
index 763a120d3b1c40f3640586e06c5833242e003d0d..c72fa7c7372758c7e7f34171f871a90c9376ff27 100644 (file)
@@ -71,7 +71,7 @@ pub fn prepare(cx: &mut Context, pkg: &Package,
 fn is_fresh(dep: &Package, loc: &Path, cx: &mut Context, targets: &[&Target])
             -> CargoResult<(bool, String)> {
     let new_pkg_fingerprint = format!("{}{}", cx.rustc_version,
-                                  try!(dep.get_fingerprint(cx.config)));
+                                      try!(dep.get_fingerprint(cx.config)));
 
     let new_fingerprint = fingerprint(new_pkg_fingerprint, hash_targets(targets));
 
index 5a5529bc3328c0b7ac2d0081d4dc2553d032691e..eabf75ac4a030a9e545d17e238c8e49525d0e7cc 100644 (file)
@@ -990,12 +990,12 @@ test!(verbose_build {
     let output = p.cargo_process("cargo-build").arg("-v")
                   .exec_with_output().assert();
     let out = str::from_utf8(output.output.as_slice()).assert();
-    let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 15);
-    let hash = hash.slice_to(17);
+    let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 16);
+    let hash = hash.slice_to(16);
     assert_eq!(out, format!("\
 {} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
-        -C metadata=test:-:0.0.0:-:file:{dir} \
-        -C extra-filename={hash} \
+        -C metadata={hash} \
+        -C extra-filename=-{hash} \
         --out-dir {dir}{sep}target \
         -L {dir}{sep}target \
         -L {dir}{sep}target{sep}deps`
@@ -1020,14 +1020,14 @@ test!(verbose_release_build {
     let output = p.cargo_process("cargo-build").arg("-v").arg("--release")
                   .exec_with_output().assert();
     let out = str::from_utf8(output.output.as_slice()).assert();
-    let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 15);
-    let hash = hash.slice_to(17);
+    let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 16);
+    let hash = hash.slice_to(16);
     assert_eq!(out, format!("\
 {} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
         --opt-level 3 \
         --cfg ndebug \
-        -C metadata=test:-:0.0.0:-:file:{dir} \
-        -C extra-filename={hash} \
+        -C metadata={hash} \
+        -C extra-filename=-{hash} \
         --out-dir {dir}{sep}target{sep}release \
         -L {dir}{sep}target{sep}release \
         -L {dir}{sep}target{sep}release{sep}deps`
@@ -1068,30 +1068,30 @@ test!(verbose_release_build_deps {
                   .exec_with_output().assert();
     let out = str::from_utf8(output.output.as_slice()).assert();
     let pos1 = out.find_str("extra-filename=").unwrap();
-    let hash1 = out.slice_from(pos1 + 15).slice_to(17);
+    let hash1 = out.slice_from(pos1 + 16).slice_to(16);
     let pos2 = out.slice_from(pos1 + 10).find_str("extra-filename=").unwrap();
-    let hash2 = out.slice_from(pos1 + 10 + pos2 + 15).slice_to(17);
+    let hash2 = out.slice_from(pos1 + 10 + pos2 + 16).slice_to(16);
     assert_eq!(out, format!("\
 {running} `rustc {dir}{sep}foo{sep}src{sep}lib.rs --crate-name foo \
         --crate-type dylib --crate-type rlib \
         --opt-level 3 \
         --cfg ndebug \
-        -C metadata=foo:-:0.0.0:-:file:{dir} \
-        -C extra-filename={hash1} \
+        -C metadata={hash1} \
+        -C extra-filename=-{hash1} \
         --out-dir {dir}{sep}target{sep}release{sep}deps \
         -L {dir}{sep}target{sep}release{sep}deps \
         -L {dir}{sep}target{sep}release{sep}deps`
 {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
         --opt-level 3 \
         --cfg ndebug \
-        -C metadata=test:-:0.0.0:-:file:{dir} \
-        -C extra-filename={hash2} \
+        -C metadata={hash2} \
+        -C extra-filename=-{hash2} \
         --out-dir {dir}{sep}target{sep}release \
         -L {dir}{sep}target{sep}release \
         -L {dir}{sep}target{sep}release{sep}deps \
         --extern foo={dir}{sep}target{sep}release{sep}deps/\
-                     {prefix}foo{hash1}{suffix} \
-        --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo{hash1}.rlib`
+                     {prefix}foo-{hash1}{suffix} \
+        --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-{hash1}.rlib`
 {compiling} foo v0.0.0 (file:{dir})
 {compiling} test v0.0.0 (file:{dir})\n",
                     running = RUNNING,
index 9af4b50042007799f30798fa8e0bc06ff98e1627..3a0f52b2c7c9ee8b06bdb6e5df31354acf8491f8 100644 (file)
@@ -1,4 +1,4 @@
-use std::io::{File, TempDir};
+use std::io::File;
 
 use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths};
 use support::{cargo_dir};